<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>React</title>
    <script src="../build/jquery.min.js"></script>
    <script src="../build/react.js"></script>
    <script src="../build/react-dom.js"></script>
    <script src="../build/browser.min.js"></script>
  </head>
  <body>
    <div id="example"></div>
    <script type="text/babel">
      let UserGist=React.createClass({
        getInitialState:function(){
          return {
            username: '',
            lastGistUrl: ''
          };
        },
        componentDidMount: function(){
          $.get(this.props.source, function(result){
            let lastGist=result[0];
            if(this.isMounted()){
              this.setState({
                username: lastGist.owner.login,
                lastGistUrl: lastGist.html_url
              });
            }
          }.bind(this));
        },
        render: function(){
          return (
            <div>
              {this.state.username}s last gist is
              <a href={this.state.lastGistUrl}>here</a>.
            </div>
          );
        }
      });

      ReactDOM.render(
        <RepoList promist={$.getJSON('https://api.github.com/search/repositories?q=javascript&sort=stars')}></RepoList>,
        document.body
      );
    </script>
  </body>
</html>
